<script type="text/javascript">
  $(document).ready(function(){

    $("#ae_form").validate({
  rules: {
    partita_iva: {
      number: true
    },
  }
});
  });


$('a.infopeso')
    .on('click', function(event) {
    $("div#chiudi").show()
    $("div#searchBox").hide()
    $("div#filterbox").hide()
    //$("div#preview").hide();
    $("div#daoaddedit").show();
    var idrrr = $(this).attr("id");
    var daos = $(this).attr("dao");
    $('div#daoaddedit').load('/anagrafiche/cliente/infopeso',{ 'idr':idrrr,"dao":daos });
    });

$("a.edit")
    .on("click", function() {
    $("div#searchBox").hide();
    $("div#chiudi").show();
    $("div#filterbox").hide();
    //$("div#preview").hide();
    $("div#daoaddedit").show();
    var idrrr = $(this).attr("id");
    var daos = $(this).attr("dao");
    $('div#daoaddedit').load('../../edit',{ 'idr':idrrr,"dao":daos })
    });

$("a#chiudilink").click(function(){
    $("div#searchBox").show();
    $("div#filterbox").show();
    $("div#preview").show();
    $("div#nav").show();
    $("div#chiudi").hide()
    $("div#daoaddedit").hide();
    $('div#preview').empty()

    });

$('a.metodo')
    .on('click', function(event) {
    $("div#chiudi").show()
    $("div#searchBox").hide()
    $("div#filterbox").hide()
    //$("div#preview").hide();
    $("div#daoaddedit").show();
    var id_cliente = $(this).attr("id_cliente");
    var daos = $(this).attr("dao");
    $('div#daoaddedit').load('/questionario_introduttivo',{ 'id_cliente':id_cliente,"dao":daos });
    });

$('a.ordine_da_cliente')
    .on('click', function() {
    $("div#chiudi").show()
    $("div#searchBox").hide()
    $("div#filterbox").hide()
    //$("div#preview").hide();

    $("div#daoaddedit").show();
    var id_cliente = $(this).attr("id_cliente");
    var daos = $(this).attr("dao");
    $('div#daoaddedit').load('/ordine_da_cliente',{ 'id_cliente':id_cliente,"dao":daos});
    });



</script>
{% if pageData['subdomain'] == "giustopeso" and pageData["role"] != "UTENTI"%}
    <a class="infopeso" href="#" dao="cliente" id="{{pageData['dao'].id}}">
        <button type="button">AGGIUNGI GENERALITÀ E PESATE</button>
    </a>
    <a class="ordine_da_cliente" href="#" dao="cliente" id_cliente="{{pageData['dao'].id}}">
        <button type="button">ORDINA ALIMENTI</button></a>
{% if pageData["role"] == "PROFESSIONISTA" %}
    <a class="metodo" href="#" dao="cliente" id_cliente="{{pageData['dao'].id}}">
        <button type="button">CREA METODO PERSONALIZZATO</button></a>
{% endif %}
    <a class="edit" href="#" dao="cliente" id="{{pageData['dao'].id}}">
        <button type="button">MODIFICA DATI FISCALI</button></a>
{% endif %}

{% if pageData["action"] == "edit"%}
<script>
$('.cmxform').ajaxForm(function() {
                alert("DATI SALVATI CORRETTAMENTE");
            });
{% if  pageData["role"] != "UTENTI" %}
    $(".infopeso").show()
    $(".ordine_da_cliente").show()
        $(".metodo").show()
        $(".edit").show()
{% endif %}
</script>


<form class="cmxform" id="ae_form" action="/anagrafiche/cliente/fromedit" method="post">
<input type="hidden" name="id" value="{{pageData['dao'].id}}"/>

{% elif pageData["action"] == "new" %}
<script>
    $(".infopeso").hide()
    $(".ordine_da_cliente").hide()
    $(".metodo").hide()
    $(".edit").hide()
</script>
<form class="cmxform" id="ae_form" action="/anagrafiche/cliente/add" method="post">
{% endif %}
<input type="hidden" name="attivita" value="{{pageData['attivita']}}"/>
<table cellpadding="4" cellspacing="0" border="0">
<tr>
    <td align="left">Cognome:</td>
    <td align="left"><input class="required" type="text" name="cognome" size="60" value='{{pageData["dao"].cognome|nonone}}' /></td>
</tr>

<tr>
    <td align="left">Nome:</td>
    <td align="left"><input  class="required" type="text" name="nome" size="60" value='{{pageData["dao"].nome|nonone}}' /></td>
</tr>
<tr>
    <td align="left">Codice Fiscale:</td>
    <td align="left"><input  class="required" type="text" name="codice_fiscale" size="20" value='{{pageData["dao"].codice_fiscale|nonone}}' /></td>
</tr>
<p><fieldset><LEGEND> <b>Informazioni Generali</b> </LEGEND>
<tr>
    <td align="left">Indirizzo:</td>
    <td align="left"><input  class="required"type="text" name="sede_legale_indirizzo" size="60" value='{{pageData["dao"].sede_legale_indirizzo|nonone}}' /></td>
</tr>
<tr>
    <td align="left">Località:</td>
    <td align="left"><input  class="required" type="text" name="sede_legale_localita" size="60" value='{{pageData["dao"].sede_legale_localita|nonone}}' /></td>
</tr>
<tr>
    <td align="left">CAP:</td>
    <td align="left"><input  class="required" type="text" name="sede_legale_cap" size="5" value='{{pageData["dao"].sede_legale_cap|nonone}}' /></td>
</tr>
<tr>
    <td align="left">Provincia:</td>
    <td align="left"><input  class="required" type="text" name="sede_legale_provincia" size="2" value='{{pageData["dao"].sede_legale_provincia|nonone}}' /></td>
</tr>
<tr>
<td colspan="2"><b>Contatti principali</b> </td>
</tr>
<tr>
    <td align="left">Telefono:</td>
    <td align="left"><input type="text" name="cliente_telefono_principale" size="60" value='{{pageData["dao"].telefono_principale|nonone}}' /></td>
</tr>
<tr>
    <td align="left">Cellulare:</td>
    <td align="left"><input  class="required" type="text" name="cliente_cellulare_principale" size="60" value='{{pageData["dao"].cellulare_principale|nonone}}' /></td>
</tr>
<tr>
    <td align="left">Email:</td>
    <td align="left"><input  type="text" name="cliente_email_principale" size="60" value='{{pageData["dao"].email_principale|nonone}}' /></td>
</tr>
<tr>
    <td align="left">Note:</td>
    <td align="left"><input type="text" name="cliente_note" size="60" value='{{pageData["dao"].note|nonone}}' /></td>
</tr>

<tr>
<td colspan="2"><b>Dati di accesso al sito</b> </td>
</tr>
<tr>
    <td align="left">Username:</td>
    <td align="left"><input type="text"  name="username" size="60" readonly="readonly" value='{{pageData["dao"].username_login|nonone}}' /></td>
</tr>
<tr>
    <td align="left">Password:</td>
    <td align="left"><input type="text"   name="password" size="60" value='{{pageData["dao"].password_login|nonone}}' /></td>
</tr>
<tr>
    <td align="left"colspan="2">
<input type="submit" name="add" value="Aggiungi" />
<input type="reset" value="Azzera" name="submit" />
    </td>
</tr>
</table>
</form>
